#include <iostream>
using std::cout;
using std::endl;

class CowString{
public:
    CowString()
    :_pstr(new char[1]())
    ,_refcount(new int(1))
    {

    }

    CowString(const CowString & rhs)
    :_pstr(rhs._pstr)
    ,_refcount(rhs._refcount)
    {
        ++*_refcount;
    }

    int refcount() const {
        return *_refcount;
    }

private:
    char * _pstr;
    int * _refcount;
};


void test(){
    CowString str1;
    cout << str1.refcount() << endl;
    CowString str2 = str1;
    cout << str1.refcount() << endl;
    cout << str2.refcount() << endl;
}

int main()
{
    test();
    return 0;
}

